<!--
@name:dialogHealthmapDisease
@author:Zhenglei
@date:16:06
@description:dialogHealthmapDisease
@update:2022/8/816:06
-->
<template>
  <el-dialog :title="title"
             :visible.sync="visible"
             :before-close="modalClose"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             width="50%">
    <el-form :model="subData"
             label-position="right"
             label-width="150px"
             ref="formModelRef"
             :rules='formModelRules'>
      <el-form-item label="病种：" prop="relationId">
        <el-select v-model="subData.relationId"
                   filterable
                   class="w-300"
                   :disabled="isEdit"
                   placeholder="请选择健康地图病种">
          <el-option v-for="item in diseasesDataSource"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态：">
        <el-select v-model="subData.healthMapDiseaseStatus"
                   class="w-300"
                   :disabled="isEdit"
                   placeholder="请选择状态">
          <el-option v-for="item in statusDataSource"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="健康建议：">
        <vue-neditor-wrap :destroy="true"
                          v-model="subData.suggest"
                          :config="myConfig"></vue-neditor-wrap>
      </el-form-item>


    </el-form>
    <p align="center">
      <el-button @click="modalClose"
                 type="info">取 消
      </el-button>
      <el-button type="primary"
                 v-prevent-re-click
                 @click="handleSave()">保 存
      </el-button>
    </p>

  </el-dialog>
</template>

<script>
import VueNeditorWrap from "vue-neditor-wrap";

export default {
  name: "dialogHealthmapDisease",
  props: {
    dataObj: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      myConfig: {
        // 你的UEditor资源存放的路径,相对于打包后的index.html
        UEDITOR_HOME_URL: this.api.uEditorHomeUrl,
        // 编辑器不自动被内容撑高
        autoHeightEnabled: false,
        // 初始容器高度
        initialFrameHeight: '418',
        // 初始容器宽度
        initialFrameWidth: '100%',
        // 关闭自动保存
        enableAutoSave: false,
        scaleEnabled: true
      },
      title: '新 增',
      subData: {
        id:null,
        healthMapDiseaseStatus:'',
        relationId:'',
        suggest:'',
        type:10,
      },
      isEdit:false,
      diseasesDataSource: [],
      statusDataSource: [
        {
          id:1,
          name:'低风险'
        },{
          id:2,
          name:'中风险'
        },{
          id:3,
          name:'高风险'
        },
      ],
      formModelRules: {
        relationId: [{required: true, message: '请选择健康地图病种', trigger: 'blur'},],
      }

    }
  },
  created() {
    if (this.dataObj.id) {
      this.title = '编 辑'
      this.isEdit=true
      this.subData.id=this.dataObj.id
      this.subData.relationId=this.dataObj.relationId
      this.subData.suggest=this.dataObj.suggest
      this.subData.healthMapDiseaseStatus=this.dataObj.healthMapDiseaseStatus

    } else {
      this.isEdit=false
      this.title = '新 增'
    }
    this.getAdvertisementHealthMapDiseaseList()
  },
  methods: {
    modalClose() {
      this.$emit('update:visible', false);
    },
    handleSave() {
      this.$refs.formModelRef.validate(valid => {
        if (valid) {
          if (this.isEdit){
            //编辑
            this.post(this.api.healthMap.updateSuggest,this.subData).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('更新成功!');
                this.$parent.getList();
                this.modalClose();
              }
            })
          }else {
            //新增
            let arr=[]
            arr.push(this.subData)
            this.post(this.api.healthMap.addSuggest,{
              jsonData:arr,
              searchType:1
            }).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('保存成功!');
                this.$parent.getList();
                this.modalClose();
              }
            })
          }

        }
      })
    },
    //查询病种
    getAdvertisementHealthMapDiseaseList() {
      this.post(this.api.healthMap.getAdvertisementHealthMapDiseaseList).then((res) => {
        if (res.data.code === '200') {
          this.diseasesDataSource = res.data.object
        }
      })
    },
  },
  components: {
    VueNeditorWrap
  }
}
</script>

<style scoped>

</style>
